package day0711;

import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) {
        //1.
        int[]  a={4,6,8,9};
        int[]  b=new int[4];
        //2.
        b[0] = 4;
        //3.
        //int数组默认值是0.
        //double数组默认值是0.0
        //boolean数组默认值是false
        //引用类型数组默认值是null
        int ele=b[0];
        System.out.println(ele);


        String[] names=new String[3];
        System.out.println(names[2]);//null
        //4.连接为String格式
        //调用Arrays.toString() 将b数组元素连接为String数据并打印
        String rs=Arrays.toString(b);  // "[4,0,0,0]"
        System.out.println(rs);
        System.arraycopy(a,1,b,1,3);
        System.out.println(Arrays.toString(b));
        //5.复制   长度
        System.out.println(a.length);

        b[ b.length -1  ]=9;

        int[] x={1,68,57,7,5};
        int[] y={5,9,7,6,6,90,6,5,7,6};
        System.arraycopy(x,0,y,y.length-x.length,x.length);
        System.out.println(Arrays.toString(y));




        int[] z=Arrays.copyOf(x, 3);   //z={1,68,57}
        System.out.println(Arrays.toString(z));


        x=Arrays.copyOf(x, 4);  //x={1,68,57,7}
        //让x代表的数组少一个元素。//模拟数组缩容1个位置
        System.out.println(Arrays.toString(x));


        x=new int[]{8,6,9,7,6};
        x=Arrays.copyOf(x, x.length+2);//让x代表的数组多两个位置。
        System.out.println(Arrays.toString(x));








        int[]  h1={5,6};
        int[]  h2={7,6,0,3,6};
        //用copyOf()对h2数组扩大两个空间
        h2=Arrays.copyOf(h2, h2.length+2);//{7,6,0,3,6,0,0}
        //将h1的两个元素arraycopy复制到h2最后的两个新位置
        System.arraycopy(h1,0, h2, h2.length-2,2);
        System.out.println(Arrays.toString(h2));




        int[]  h4={7,6,0,3,6};
        int [] z2= changeBig(h4);
        System.out.println(Arrays.toString(z2));//能否打印长度为10的数组
    }

    private static int[] changeBig(int[] h4) {
        int[] z=Arrays.copyOf(h4,  h4.length*2);   //z={1,68,57}
        System.out.println(Arrays.toString(z));
        return z;
    }
}
